//
//  ViewController.m
//  15网易云新闻条
//
//  Created by dllo on 16/8/3.
//  Copyright © 2016年 YMJ. All rights reserved.
//

#import "ViewController.h"
#import "YMJLayout.h"
#import "YMJCollectionViewCell.h"
#import "SelfSizeTool.h"

@interface ViewController ()<UICollectionViewDataSource,UICollectionViewDelegate,YMJLayoutDelegate>
@property (nonatomic, strong) UICollectionView *coll;
@property (nonatomic, strong) NSMutableArray *dataArr;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.

    self.navigationController.navigationBar.translucent = NO;
    YMJLayout *lay = [YMJLayout new];
    lay.delegate = self;
    self.coll = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, 414, 44) collectionViewLayout:lay];

    [self.view addSubview:_coll];
    _coll.backgroundColor = [UIColor yellowColor];
    _coll.delegate = self;
    _coll.dataSource = self;
    
    [_coll registerNib:[UINib nibWithNibName:@"YMJCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:@"1"];
    _dataArr = [NSMutableArray arrayWithObjects:@"爱打球",@"去日日日啊啊啊",@"商务服务",@"发我的嗷嗷啊娃",@"如何维护文化", @"爱打球",@"去日日日啊啊啊",@"商务服务",@"发我的嗷嗷啊娃",@"如何维护文化",@"爱打球",@"去日日日啊啊啊",@"商务服务",@"发我的嗷嗷啊娃",@"如何维护文化",nil];
}
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout widthForItemAtIndexPath:(NSIndexPath *)indexPath height:(CGFloat)height {
    return [SelfSizeTool selfSizeHeightWithString:_dataArr[indexPath.row] height:height font:[UIFont systemFontOfSize:17]];
    
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return _dataArr.count;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    YMJCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"1" forIndexPath:indexPath];
    cell.backgroundColor = [UIColor greenColor];
    cell.label.text = _dataArr[indexPath.row];
    return cell;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
